package com.lagou.rpc.consumer;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.consumer.task.Task;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 11:05 上午 2021/12/3
 */
@SpringBootApplication
public class ClientBootstrapApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(ClientBootstrapApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        RpcClientProxy rpcClientProxy=new RpcClientProxy();
        rpcClientProxy.watch();
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(4);
        scheduledThreadPool.schedule(new Task(),5, TimeUnit.SECONDS);
    }

    //添加注解，注册到ioc容器中，便于在controller中调用
    @Bean
    public IUserService IUserService() {
        IUserService userService = (IUserService) RpcClientProxy.createProxy(IUserService.class);
        return userService;
    }


}
